import gria.*
import auth.User
import auth.Role
import org.apache.commons.codec.digest.DigestUtils

class BootStrap {

     def init = { servletContext ->
    
     if (true)
     {
      def adminRole = new Role(name:"Administrator")
      def userRole = new Role(name:"User")
      
      assert adminRole.save()
      assert userRole.save()
        
      def user = new User(email:"michael.turner3@baesystems.com", password:DigestUtils.shaHex("testing"), userName:"Mike")
 
      println "user ${user.email} has been created with password ${user.password}"
      assert user.email
      assert user.addToRoles(adminRole)
      assert user.addToRoles(userRole)
      if (!user.save())
      {
       user.errors.each {
                println it
            } 
      }
         

        HashMap args = new HashMap<String, Class>();
        args.put("TwoD", boolean.class);
        args.put("TolC", int.class);
            

        
        FileType dat = new FileType(type:"DAT File",description:"A DAT File", extension:".dat" )
        FileType bac = new FileType(type:"BAC File",description:"A BAC File", extension:".bac" )
        FileType fro = new FileType(type:"FRO File",description:"A FRO File", extension:".fro" )
        ApplicationArgument twod = new ApplicationArgument(name:"Two D", argumentString:"-2d", type:"boolean", defaultValue:"false", notes:"Is this a 2d case?", tooltip:"2d?");  
        ApplicationArgument tolc = new ApplicationArgument(name:"Equals Tolerance", argumentString:"-tolc", type:"double", defaultValue:"0.0001", notes:"Equals Tolerance", tooltip:"TolC");
        
        dat.save();
        bac.save();
        fro.save();
        
        new GriaApplication(applicationName:"Flite ST",applicationString:"http://www.baegrid.co.uk/2008/cfd/flite3d/st",
                serviceAddress:"https://glkas0650.greenlnk.net:9443/gria-basic-app-services/services/JobService?wsdl",inputs:[bac, dat],
                outputs:[fro],arguments:[twod,tolc]).save()
      } 
    }
     
     def destroy = {
     }
} 